using System;
using System.Linq;
using Abp.Zero.Configuration;
using JYJ.AiYard.EntityFrameworkCore;

namespace JYJ.AiYard.Seed.Tenants
{
    public class DefaultSettingsBuilder
    {
        private readonly AiYardDbContext _context;
        private readonly int _tenantId;

        public DefaultSettingsBuilder(AiYardDbContext context, int tenantId)
        {
            _context = context;
            _tenantId = tenantId;
        }

        public void Create()
        {

            DefaultSetings();
            //CreateMemberRoles();
        }


        private void DefaultSetings()
        {
            var setting = _context.Settings.Where(o => o.Name == AbpZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin && (o.TenantId == this._tenantId || o.TenantId==null )).FirstOrDefault();
            if (setting == null)
            { 
                _context.Settings.Add(new Abp.Configuration.Setting(null, null, AbpZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin, "false"));
                _context.Settings.Add(new Abp.Configuration.Setting(_tenantId, null, AbpZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin, "false"));
            } 
            _context.SaveChanges();

        }
    }
}
